//
//  MQSavePicAndVideoTableViewCell.m
//  MQ
//
//  Created by 曾杰 on 15/10/28.
//  Copyright © 2015年 徐永祥. All rights reserved.
//

#import "MQSavePicAndVideoTableViewCell.h"
#import <UIImageView+WebCache.h>
@implementation MQSavePicAndVideoTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, MQWidth-20, 30)];
        [self.contentView addSubview:_contentLabel];
        _BimageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 50, MQWidth-20, 30)];
        [self.contentView addSubview:_BimageView];
        _clearButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _clearButton.frame = CGRectMake(MQWidth-40, 90, 30, 30);
        [self.contentView addSubview:_clearButton];
    }
    return self;
}
//赋值
- (void)cellWithModel:(MQPictureInsterestingModel *)model
{
    [self.BimageView sd_setImageWithURL:[NSURL URLWithString:model.wpic_middle]];
    _contentLabel.text = model.wbody;
    CGFloat strHeight = [MQSavePicAndVideoTableViewCell cellForHeight:model.wbody];
    self.contentLabel.frame = CGRectMake(10, 10, MQWidth-20, strHeight);
    self.BimageView.frame = CGRectMake(10, strHeight+20, MQWidth-40, [model.wpic_m_height floatValue]);
    self.clearButton.frame = CGRectMake(MQWidth-40, strHeight+30+[model.wpic_m_height floatValue], 30, 30);
    [self.clearButton setImage:[UIImage imageNamed:@"shanchu"] forState:(UIControlStateNormal)];
    
}
//文字自适应
+ (CGFloat)cellForHeight:(NSString *)string
{
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:18] forKey:NSFontAttributeName];
    CGRect bound = [string boundingRectWithSize:CGSizeMake(MQWidth-20, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return bound.size.height;
}
//返回的行高
+ (CGFloat)HeightForModel:(MQPictureInsterestingModel *)model
{
    CGFloat strHeight = [MQSavePicAndVideoTableViewCell cellForHeight:model.wbody];
    return strHeight+30+[model.wpic_m_height floatValue]+40;
}







- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
